Redo CSS style printing
authorMatthias Clasen <mclasen@redhat.com>
Sun, 3 Jan 2016 20:34:08 +0000 (15:34 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 3 Jan 2016 20:36:48 +0000 (15:36 -0500)
Drop the custom style printing implementation in gtkcssnode.c and
instead reuse the existing gtk_css_style_print function, extending
it a bit to suit our needs.

Instead of computing values, just recognize initial values by
having no CSS section. Also do away with the show-initial flag, and
just always filter out initial values. The flag can come back when
it is needed.

gtk/gtkcssnode.c
gtk/gtkcssstyle.c
gtk/gtkcssstyleprivate.h
gtk/gtkstylecontext.c
gtk/gtkstylecontext.h

index a828d9f8e10d69b6860ac237817fe30ac8b69ff6..676d0b27a80411f038d5f761d881878df26ed3b8 100644 (file)
@@ -1523,90 +1523,6 @@ gtk_css_node_get_style_provider (GtkCssNode *cssnode)
   return GTK_STYLE_PROVIDER_PRIVATE (_gtk_settings_get_style_cascade (gtk_settings_get_default (), 1));
 }
 
-static gboolean
-gtk_css_node_has_initial_value (GtkCssNode          *cssnode,
-                                GtkCssStyleProperty *prop)
-{
-  GtkCssNode *parent_node;
-  GtkCssStyle *style, *parent_style;
-  GtkCssValue *value, *initial, *computed;
-  GtkStyleProviderPrivate *provider;
-  gboolean is_initial;
-  guint id;
-
-  id = _gtk_css_style_property_get_id (prop);
-  style = gtk_css_node_get_style (cssnode);
-  value = gtk_css_style_get_value (style, id);
-
-  parent_node = gtk_css_node_get_parent (cssnode);
-  parent_style = parent_node ? gtk_css_node_get_style (parent_node) : NULL;
-  provider = gtk_css_node_get_style_provider (cssnode);
-
-  initial = _gtk_css_style_property_get_initial_value (prop);
-  computed = _gtk_css_value_compute (initial, id, provider, style, parent_style);
-
-  is_initial = _gtk_css_value_equal (value, computed);
-
-  _gtk_css_value_unref (computed);
-
-  return is_initial;
-}
-
-static void
-append_value (GtkCssNode          *cssnode,
-              GtkCssStyleProperty *prop,
-              GString             *string,
-              guint                indent)
-{
-  GtkCssValue *value;
-  GtkCssStyle *style;
-  GtkCssSection *section;
-  const char *name;
-  guint id;
-
-  id = _gtk_css_style_property_get_id (prop);
-  name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
-  style = gtk_css_node_get_style (cssnode);
-  value = gtk_css_style_get_value (style, id);
-
-  g_string_append_printf (string, "%*s%s: ", indent, "", name);
-
-  _gtk_css_value_print (value, string);
-
-  section = gtk_css_style_get_section (style, id);
-  if (section)
-    {
-      g_string_append (string, " (");
-      _gtk_css_section_print (section, string);
-      g_string_append (string, ")");
-    }
-
-  g_string_append_c (string, '\n');
-}
-
-static void
-append_style (GtkCssNode                *cssnode,
-              GtkStyleContextPrintFlags  flags,
-              GString                   *string,
-              guint                      indent)
-{
-  int i;
-
-  if (!(flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE))
-    return;
-
-  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
-    {
-      GtkCssStyleProperty *prop;
-
-      prop = _gtk_css_style_property_lookup_by_id (i);
-
-      if ((flags & GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL) ||
-          !gtk_css_node_has_initial_value (cssnode, prop))
-        append_value (cssnode, prop, string, indent);
-    }
-}
-
 void
 gtk_css_node_print (GtkCssNode                *cssnode,
                     GtkStyleContextPrintFlags  flags,
@@ -1627,7 +1543,8 @@ gtk_css_node_print (GtkCssNode                *cssnode,
 
   g_string_append_c (string, '\n');
 
-  append_style (cssnode, flags, string, indent + 2);
+  if (flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE)
+    gtk_css_style_print (gtk_css_node_get_style (cssnode), string, indent + 2, TRUE);
 
   if (flags & GTK_STYLE_CONTEXT_PRINT_RECURSE)
     {
index d577dc79d3bf191251b2f50aacd7d86ae63b5623..812c8dc75a1a49d8265d0c5bbac119411504e2ad 100644 (file)
@@ -114,10 +114,11 @@ gtk_css_style_is_static (GtkCssStyle *style)
   return GTK_CSS_STYLE_GET_CLASS (style)->is_static (style);
 }
 
-
 void
 gtk_css_style_print (GtkCssStyle *style,
-                     GString     *string)
+                     GString     *string,
+                     guint        indent,
+                     gboolean     skip_initial)
 {
   guint i;
 
@@ -126,18 +127,31 @@ gtk_css_style_print (GtkCssStyle *style,
 
   for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
     {
-      GtkCssSection *section = gtk_css_style_get_section (style, i);
-      g_string_append (string, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i))));
-      g_string_append (string, ": ");
-      _gtk_css_value_print (gtk_css_style_get_value (style, i), string);
-      g_string_append (string, ";");
+      GtkCssSection *section;
+      GtkCssStyleProperty *prop;
+      GtkCssValue *value;
+      const char *name;
+
+      section = gtk_css_style_get_section (style, i);
+      if (!section && skip_initial)
+        continue;
+
+      prop = _gtk_css_style_property_lookup_by_id (i);
+      name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
+      value = gtk_css_style_get_value (style, i);
+
+      g_string_append_printf (string, "%*s%s: ", indent, "", name);
+      _gtk_css_value_print (value, string);
+      g_string_append_c (string, ';');
+
       if (section)
         {
           g_string_append (string, " /* ");
           _gtk_css_section_print (section, string);
           g_string_append (string, " */");
         }
-      g_string_append (string, "\n");
+
+      g_string_append_c (string, '\n');
     }
 }
 
@@ -150,7 +164,7 @@ gtk_css_style_to_string (GtkCssStyle *style)
 
   string = g_string_new ("");
 
-  gtk_css_style_print (style, string);
+  gtk_css_style_print (style, string, 0, FALSE);
 
   return g_string_free (string, FALSE);
 }
index ff0298082f3e41f3c2aaf0a9d960af7891d23399..d5cd40526bb4b2863e53bd79a83a593833380152 100644 (file)
@@ -71,7 +71,9 @@ gboolean                gtk_css_style_is_static                 (GtkCssStyle
 
 char *                  gtk_css_style_to_string                 (GtkCssStyle            *style);
 void                    gtk_css_style_print                     (GtkCssStyle            *style,
-                                                                 GString                *string);
+                                                                 GString                *string,
+                                                                 guint                   indent,
+                                                                 gboolean                skip_initial);
 
 G_END_DECLS
 
index 30173c7c158f26f71ba2e13dfb9aa76a01a6f40e..26b578f713dc966713a3756b683b7e8d8f79d989 100644 (file)
@@ -3226,10 +3226,6 @@ _gtk_style_context_is_background_opaque (GtkStyleContext *context)
  *     CSS nodes starting at the style context's node
  * @GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE: Show the values of the
  *     CSS properties for each node
- * @GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL: Show the values of the
- *     CSS properties even if they match the initial value. By default,
- *     values are only shown if they are different from the initial
- *     value.
  *
  * Flags that modify the behavior of gtk_style_context_to_string().
  * New values may be added to this enumeration.
index d6fe5754f7eb0ad68b312a79fe0e79b224ca9961..e3481b81230545b1bdd85516311cc7e0581b189a 100644 (file)
@@ -1211,8 +1211,7 @@ void   gtk_draw_insertion_cursor    (GtkWidget          *widget,
 typedef enum {
   GTK_STYLE_CONTEXT_PRINT_NONE         = 0,
   GTK_STYLE_CONTEXT_PRINT_RECURSE      = 1 << 0,
-  GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE   = 1 << 1,
-  GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL = 1 << 2
+  GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE   = 1 << 1
 } GtkStyleContextPrintFlags;
 
 GDK_AVAILABLE_IN_3_20